# coding=gbk
"""
Created on 2016/6/16 0016

@author: Blunce

@about:

"""
from itertools import count, islice
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
from utils.myUtils import read_csv, save_as_csv

ALL_FILE_NAMES = [
    # "Normal_beat",
    "Left_bundle_branch_block_beat",
    "Right_bundle_branch_block_beat",
    "Premature_ventricular_contraction",
    "Paced_beat",
    "Atrial_premature_beat",
    "Fusion_of_paced_and_normal_beat",
    "Fusion_of_ventricular_and_normal_beat",
    "Ventricular_flutter_wave",
    "Aberrated_atrial_premature_beat"
]

PATH_DATA = os.getcwd()[:-10] + "data" + os.sep + "preprocess_data" + os.sep
PATH_TMP = os.getcwd()[:-10] + "data" + os.sep + "preprocess_data2" + os.sep


class Preprecess2:
    def __init__(self):
        pass

    def __show_ecg(self, y):
        plt.plot(y)
        plt.show()

    def extract_9_ecg(self):
        for filename in ALL_FILE_NAMES:
            lines = read_csv(PATH_DATA + filename + ".csv")
            data = []
            for i in range(len(lines)):
                if len(data) > 50:
                    break
                ecg = lines[i]
                plt.title(filename)
                plt.suptitle(str(i) + "  /  " + str(len(lines)))
                plt.plot(ecg)
                plt.show()
                isSaveIt = raw_input("Will it be saved?\n")
                if isSaveIt == "y":
                    data.append(ecg)
            save_as_csv(data, PATH_TMP + filename + ".csv")


def getEnter():
    x = raw_input("Please Enter:\n")
    if x == "\n":
        print "hello"
    else:
        print "Hello"


if __name__ == '__main__':
    print "**************start**************\n\n"

    # getEnter()
    Preprecess2().extract_9_ecg()

    print "\n\n**************end**************"
